package com.acme.bankapp.service.bank;

import java.util.LinkedList;
import java.util.List;

import com.acme.bankapp.domain.bank.Email;

public class Queue<T> {
	private List<T> arr = new LinkedList<T>();
	private Object mutex = new Object();
	private boolean toBeClosed = false;
	
	public void push(final T obj) {
		synchronized (mutex) {
			if (!toBeClosed) {
				arr.add(obj);
			}
			mutex.notifyAll();
		}
	}
	
	public T pop() throws InterruptedException {
		synchronized (mutex) {
			while (arr.isEmpty()){
					mutex.wait();
			}
			return arr.remove(0);
		}
	}
	
	public boolean isEmpty() {
		synchronized (mutex) {
			return arr.isEmpty();
		}
	}
}
